"GSK_PT3_1", "GSK_PT3_2", "GSK_PT3_3",    "GSK_PT7_1", "GSK_PT7_2", "GSK_PT7_3",  "GSK_PT10_1", "GSK_PT10_2", "GSK_PT10_3",
"Isotretinoin_and_TAZ_PT3_1", "Isotretinoin_and_TAZ_PT3_2", "Isotretinoin_and_TAZ_PT3_3",    "Isotretinoin_and_TAZ_PT7_1", "Isotretinoin_and_TAZ_PT7_2", "Isotretinoin_and_TAZ_PT7_3",  "Isotretinoin_and_TAZ_PT10_1", "Isotretinoin_and_TAZ_PT10_2", "Isotretinoin_and_TAZ_PT10_3",
"Isotretinoin_and_GSK_PT3_1", "Isotretinoin_and_GSK_PT3_2", "Isotretinoin_and_GSK_PT3_3",    "Isotretinoin_and_GSK_PT7_1", "Isotretinoin_and_GSK_PT7_2", "Isotretinoin_and_GSK_PT7_3",  "Isotretinoin_and_GSK_PT10_1", "Isotretinoin_and_GSK_PT10_2", "Isotretinoin_and_GSK_PT10_3", "k_clusters")# kdf <- kdf[, col_order]
#check reorder
colnames(kdf)
# format and write output table
kdf_table<-kdf
kdf_table$gene<-rownames(kdf)
kdf_table<-kdf_table[,c('gene','k_clusters')]
names(kdf_table)<-c('gene','cluster')
write.table(kdf_table,file=paste0('cluster_details_k',k,'_alllines.txt'),row.names=FALSE,quote=FALSE,col.names=TRUE)
#check reorder
colnames(kdf)
kdf <- scaledata
kdf <- as.data.frame(kdf)
# conduct clustering
res_k<-hkmeans(kdf,k,hc.method='complete')
kdf$k_clusters<-res_k$cluster
kdf$k_clusters<-as.character(kdf$k_clusters)
kdf<-kdf[order(kdf$k_clusters),]
# extract number of genes in each cluster
for(i in 1:k){
print(nrow(subset(kdf,k_clusters==i)))
}
# format and write output table
kdf_table<-kdf
kdf_table$gene<-rownames(kdf)
kdf_table<-kdf_table[,c('gene','k_clusters')]
names(kdf_table)<-c('gene','cluster')
write.table(kdf_table,file=paste0('cluster_details_k',k,'_alllines.txt'),row.names=FALSE,quote=FALSE,col.names=TRUE)
#reorder columns to time order
col_order <- c("DMSO_PT3_1", "DMSO_PT3_2", "DMSO_PT3_3",
"DMSO_PT7_1", "DMSO_PT7_2", "DMSO_PT7_3", "DMSO_PT10_1", "DMSO_PT10_2", "DMSO_PT10_3",
"Isotretinoin_PT3_1", "Isotretinoin_PT3_2", "Isotretinoin_PT3_3", "Isotretinoin_PT7_1", "Isotretinoin_PT7_2", "Isotretinoin_PT7_3", "Isotretinoin_PT10_1", "Isotretinoin_PT10_2", "Isotretinoin_PT10_3",
"TAZ_PT3_1", "TAZ_PT3_2", "TAZ_PT3_3",    "TAZ_PT7_1", "TAZ_PT7_2", "TAZ_PT7_3",  "TAZ_PT10_1", "TAZ_PT10_2", "TAZ_PT10_3",
"GSK_PT3_1", "GSK_PT3_2", "GSK_PT3_3",    "GSK_PT7_1", "GSK_PT7_2", "GSK_PT7_3",  "GSK_PT10_1", "GSK_PT10_2", "GSK_PT10_3",
"Isotretinoin_and_TAZ_PT3_1", "Isotretinoin_and_TAZ_PT3_2", "Isotretinoin_and_TAZ_PT3_3",    "Isotretinoin_and_TAZ_PT7_1", "Isotretinoin_and_TAZ_PT7_2", "Isotretinoin_and_TAZ_PT7_3",  "Isotretinoin_and_TAZ_PT10_1", "Isotretinoin_and_TAZ_PT10_2", "Isotretinoin_and_TAZ_PT10_3",
"Isotretinoin_and_GSK_PT3_1", "Isotretinoin_and_GSK_PT3_2", "Isotretinoin_and_GSK_PT3_3",    "Isotretinoin_and_GSK_PT7_1", "Isotretinoin_and_GSK_PT7_2", "Isotretinoin_and_GSK_PT7_3",  "Isotretinoin_and_GSK_PT10_1", "Isotretinoin_and_GSK_PT10_2", "Isotretinoin_and_GSK_PT10_3", "k_clusters")# kdf <- kdf[, col_order]
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
k<-3
res.k<-hkmeans(scaledata,k,hc.method='complete')
png(paste0('alllines_kmeans_k',k,'_clusters.png'),width=350,height=300)
print(fviz_cluster(res.k, ellipse=FALSE,labelsize=6,ggtheme = theme_classic(),geom=c('point'),pointsize=1,stand=TRUE,shape='circle')+scale_colour_manual(values = c("darkorange", "green4","mediumvioletred",'royalblue3','darkgoldenrod2','red3','grey78','grey28')))
dev.off()
# Silhouette method
png('Silhouette_method.png',width=400,height=250)
fviz_nbclust(scaledata, kmeans, method = "silhouette")+
labs(subtitle = "Silhouette method")
dev.off()
kdf <- scaledata
kdf <- as.data.frame(kdf)
# conduct clustering
res_k<-hkmeans(kdf,k,hc.method='complete')
kdf$k_clusters<-res_k$cluster
kdf$k_clusters<-as.character(kdf$k_clusters)
kdf<-kdf[order(kdf$k_clusters),]
# extract number of genes in each cluster
for(i in 1:k){
print(nrow(subset(kdf,k_clusters==i)))
}
# format and write output table
kdf_table<-kdf
kdf_table$gene<-rownames(kdf)
kdf_table<-kdf_table[,c('gene','k_clusters')]
names(kdf_table)<-c('gene','cluster')
write.table(kdf_table,file=paste0('cluster_details_k',k,'_alllines.txt'),row.names=FALSE,quote=FALSE,col.names=TRUE)
#reorder columns to time order
col_order <- c("DMSO_PT3_1", "DMSO_PT3_2", "DMSO_PT3_3",
"DMSO_PT7_1", "DMSO_PT7_2", "DMSO_PT7_3", "DMSO_PT10_1", "DMSO_PT10_2", "DMSO_PT10_3",
"Isotretinoin_PT3_1", "Isotretinoin_PT3_2", "Isotretinoin_PT3_3", "Isotretinoin_PT7_1", "Isotretinoin_PT7_2", "Isotretinoin_PT7_3", "Isotretinoin_PT10_1", "Isotretinoin_PT10_2", "Isotretinoin_PT10_3",
"TAZ_PT3_1", "TAZ_PT3_2", "TAZ_PT3_3",    "TAZ_PT7_1", "TAZ_PT7_2", "TAZ_PT7_3",  "TAZ_PT10_1", "TAZ_PT10_2", "TAZ_PT10_3",
"GSK_PT3_1", "GSK_PT3_2", "GSK_PT3_3",    "GSK_PT7_1", "GSK_PT7_2", "GSK_PT7_3",  "GSK_PT10_1", "GSK_PT10_2", "GSK_PT10_3",
"Isotretinoin_and_TAZ_PT3_1", "Isotretinoin_and_TAZ_PT3_2", "Isotretinoin_and_TAZ_PT3_3",    "Isotretinoin_and_TAZ_PT7_1", "Isotretinoin_and_TAZ_PT7_2", "Isotretinoin_and_TAZ_PT7_3",  "Isotretinoin_and_TAZ_PT10_1", "Isotretinoin_and_TAZ_PT10_2", "Isotretinoin_and_TAZ_PT10_3",
"Isotretinoin_and_GSK_PT3_1", "Isotretinoin_and_GSK_PT3_2", "Isotretinoin_and_GSK_PT3_3",    "Isotretinoin_and_GSK_PT7_1", "Isotretinoin_and_GSK_PT7_2", "Isotretinoin_and_GSK_PT7_3",  "Isotretinoin_and_GSK_PT10_1", "Isotretinoin_and_GSK_PT10_2", "Isotretinoin_and_GSK_PT10_3", "k_clusters")# kdf <- kdf[, col_order]
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
# visual check of the value of k choice
k<-4
res.k<-hkmeans(scaledata,k,hc.method='complete')
png(paste0('alllines_kmeans_k',k,'_clusters.png'),width=350,height=300)
print(fviz_cluster(res.k, ellipse=FALSE,labelsize=6,ggtheme = theme_classic(),geom=c('point'),pointsize=1,stand=TRUE,shape='circle')+scale_colour_manual(values = c("darkorange", "green4","mediumvioletred",'royalblue3','darkgoldenrod2','red3','grey78','grey28')))
dev.off()
# Silhouette method
png('Silhouette_method.png',width=400,height=250)
fviz_nbclust(scaledata, kmeans, method = "silhouette")+
labs(subtitle = "Silhouette method")
dev.off()
kdf <- scaledata
kdf <- as.data.frame(kdf)
# conduct clustering
res_k<-hkmeans(kdf,k,hc.method='complete')
kdf$k_clusters<-res_k$cluster
kdf$k_clusters<-as.character(kdf$k_clusters)
kdf<-kdf[order(kdf$k_clusters),]
# extract number of genes in each cluster
for(i in 1:k){
print(nrow(subset(kdf,k_clusters==i)))
}
# format and write output table
kdf_table<-kdf
kdf_table$gene<-rownames(kdf)
kdf_table<-kdf_table[,c('gene','k_clusters')]
names(kdf_table)<-c('gene','cluster')
write.table(kdf_table,file=paste0('cluster_details_k',k,'_alllines.txt'),row.names=FALSE,quote=FALSE,col.names=TRUE)
library(ComplexHeatmap)
library(plyr)
library(factoextra)
library(scales)
library(circlize)
library(stringr)
#reorder columns to time order
col_order <- c("DMSO_PT3_1", "DMSO_PT3_2", "DMSO_PT3_3",
"DMSO_PT7_1", "DMSO_PT7_2", "DMSO_PT7_3", "DMSO_PT10_1", "DMSO_PT10_2", "DMSO_PT10_3",
"Isotretinoin_PT3_1", "Isotretinoin_PT3_2", "Isotretinoin_PT3_3", "Isotretinoin_PT7_1", "Isotretinoin_PT7_2", "Isotretinoin_PT7_3", "Isotretinoin_PT10_1", "Isotretinoin_PT10_2", "Isotretinoin_PT10_3",
"TAZ_PT3_1", "TAZ_PT3_2", "TAZ_PT3_3",    "TAZ_PT7_1", "TAZ_PT7_2", "TAZ_PT7_3",  "TAZ_PT10_1", "TAZ_PT10_2", "TAZ_PT10_3",
"GSK_PT3_1", "GSK_PT3_2", "GSK_PT3_3",    "GSK_PT7_1", "GSK_PT7_2", "GSK_PT7_3",  "GSK_PT10_1", "GSK_PT10_2", "GSK_PT10_3",
"Isotretinoin_and_TAZ_PT3_1", "Isotretinoin_and_TAZ_PT3_2", "Isotretinoin_and_TAZ_PT3_3",    "Isotretinoin_and_TAZ_PT7_1", "Isotretinoin_and_TAZ_PT7_2", "Isotretinoin_and_TAZ_PT7_3",  "Isotretinoin_and_TAZ_PT10_1", "Isotretinoin_and_TAZ_PT10_2", "Isotretinoin_and_TAZ_PT10_3",
"Isotretinoin_and_GSK_PT3_1", "Isotretinoin_and_GSK_PT3_2", "Isotretinoin_and_GSK_PT3_3",    "Isotretinoin_and_GSK_PT7_1", "Isotretinoin_and_GSK_PT7_2", "Isotretinoin_and_GSK_PT7_3",  "Isotretinoin_and_GSK_PT10_1", "Isotretinoin_and_GSK_PT10_2", "Isotretinoin_and_GSK_PT10_3", "k_clusters")# kdf <- kdf[, col_order]
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = FALSE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(test[,1:(ncol(test)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('RA',9),rep('TAZ',9), rep("GSK", 9), rep("RA_and_TAZ", 9), rep("RA_and_GSK",9)),levels=c('DMSO','RA','TAZ', 'GSK','RA_and_TAZ','RA_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(test[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1_and_h2
test <- kdf[kdf$k_clusters == '2',]
h1<-Heatmap(as.matrix(test[,1:(ncol(test)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('RA',9),rep('TAZ',9), rep("GSK", 9), rep("RA_and_TAZ", 9), rep("RA_and_GSK",9)),levels=c('DMSO','RA','TAZ', 'GSK','RA_and_TAZ','RA_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(test[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('cluster_2_only_Hmap_kmeans_k',k,'_clusters.tiff'),width=2000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
levels(kdf)
col_order <- c("DMSO_PT3_1", "DMSO_PT3_2", "DMSO_PT3_3",
"DMSO_PT7_1", "DMSO_PT7_2", "DMSO_PT7_3", "DMSO_PT10_1", "DMSO_PT10_2", "DMSO_PT10_3",
"Isotretinoin_PT3_1", "Isotretinoin_PT3_2", "Isotretinoin_PT3_3", "Isotretinoin_PT7_1", "Isotretinoin_PT7_2", "Isotretinoin_PT7_3", "Isotretinoin_PT10_1", "Isotretinoin_PT10_2", "Isotretinoin_PT10_3",
"TAZ_PT3_1", "TAZ_PT3_2", "TAZ_PT3_3",    "TAZ_PT7_1", "TAZ_PT7_2", "TAZ_PT7_3",  "TAZ_PT10_1", "TAZ_PT10_2", "TAZ_PT10_3",
"GSK_PT3_1", "GSK_PT3_2", "GSK_PT3_3",    "GSK_PT7_1", "GSK_PT7_2", "GSK_PT7_3",  "GSK_PT10_1", "GSK_PT10_2", "GSK_PT10_3",
"Isotretinoin_and_TAZ_PT3_1", "Isotretinoin_and_TAZ_PT3_2", "Isotretinoin_and_TAZ_PT3_3",    "Isotretinoin_and_TAZ_PT7_1", "Isotretinoin_and_TAZ_PT7_2", "Isotretinoin_and_TAZ_PT7_3",  "Isotretinoin_and_TAZ_PT10_1", "Isotretinoin_and_TAZ_PT10_2", "Isotretinoin_and_TAZ_PT10_3",
"Isotretinoin_and_GSK_PT3_1", "Isotretinoin_and_GSK_PT3_2", "Isotretinoin_and_GSK_PT3_3",    "Isotretinoin_and_GSK_PT7_1", "Isotretinoin_and_GSK_PT7_2", "Isotretinoin_and_GSK_PT7_3",  "Isotretinoin_and_GSK_PT10_1", "Isotretinoin_and_GSK_PT10_2", "Isotretinoin_and_GSK_PT10_3", "k_clusters")
kdf <- kdf[, col_order]
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
#check reorder
colnames(kdf)
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3000,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3500,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
dev.off()
png(filename="heatmap_k_4.png", width=3600, bg="white")
h1<-Heatmap(as.matrix(kdf[,1:(ncol(kdf)-1)]),cluster_rows=TRUE,cluster_columns=FALSE,use_raster=FALSE,row_dend_reorder = TRUE,show_row_dend = FALSE,column_split=factor(c(rep('DMSO',9),rep('Isotretinoin',9),rep('TAZ',9), rep("GSK", 9), rep("Isotretinoin_and_TAZ", 9), rep("Isotretinoin_and_GSK",9)),levels=c('DMSO','Isotretinoin','TAZ', 'GSK','Isotretinoin_and_TAZ','Isotretinoin_and_GSK')),show_row_names=FALSE,show_column_names = FALSE, heatmap_legend_param = list(title = "Z-score"))
h2<-Heatmap(as.matrix(kdf[,'k_clusters']),cluster_columns=FALSE,cluster_rows=FALSE, heatmap_legend_param = list(title = "Cluster"))
hlist <- h1+h2
tiff(paste0('Heatmap_k_',k,'_clusters.tiff'),width=3600,height=3000,res=300)
draw(hlist, row_split = kdf$hk_clusters, cluster_row_slices = TRUE,cluster_rows=FALSE, row_dend_reorder = TRUE,show_row_dend = FALSE)
library(clusterProfiler)
bg_universe<-DEgenes
length(bg_universe)
GO_pathways <- gmtPathways("C:/Users/Christina/Documents/GSEA .gmt/c5.go.v2022.1.Hs.symbols.gmt")
clusters<-read.table("~/Neuroblastoma RNAseq analysis/K-means/cluster_details_k3_alllines.txt",stringsAsFactors = FALSE,header=TRUE)
clusters
unique(clusters$cluster)
clusters<-read.table("~/Neuroblastoma RNAseq analysis/K-means/cluster_details_k4_alllines.txt",stringsAsFactors = FALSE,header=TRUE)
kdf <- scaledata
kdf <- as.data.frame(kdf)
# conduct clustering
res_k<-hkmeans(kdf,k,hc.method='complete')
kdf$k_clusters<-res_k$cluster
kdf$k_clusters<-as.character(kdf$k_clusters)
kdf<-kdf[order(kdf$k_clusters),]
# extract number of genes in each cluster
for(i in 1:k){
print(nrow(subset(kdf,k_clusters==i)))
}
# format and write output table
kdf_table<-kdf
kdf_table$gene<-rownames(kdf)
kdf_table<-kdf_table[,c('gene','k_clusters')]
names(kdf_table)<-c('gene','cluster')
write.table(kdf_table,file=paste0('cluster_details_k',k,'_alllines.txt'),row.names=FALSE,quote=FALSE,col.names=TRUE)
clusters<-read.table("~/Neuroblastoma RNAseq analysis/SIGNIFICANT DEGs/cluster_details_k4_alllines.txt",stringsAsFactors = FALSE,header=TRUE)
k
clusters<-read.table("~/Neuroblastoma RNAseq analysis/SIGNIFICANT_DEGs/cluster_details_k4_alllines.txt",stringsAsFactors = FALSE,header=TRUE)
GOtypes<-c('ALL')
for(GOtype in GOtypes){
for(i in 1:k){
geneList<-subset(clusters,cluster==i)$gene
ego <- enrichGO(geneList, OrgDb = "org.Hs.eg.db", ont=GOtype, pAdjustMethod='fdr', pvalueCutoff=0.01,universe=bg_universe,keyType='SYMBOL',minGSSize=20,maxGSSize=500)
ego_df<-data.frame(ego,stringsAsFactors = FALSE)
ego_df<-ego_df[order(ego_df$p.adjust),]
write.csv(ego_df[,c(2,3,4,6,8)],file = paste0('clusters_',i,'_',GOtype,'.csv'),quote=FALSE,row.names=FALSE)
ego_df$neglog10padj<--log(ego_df$p.adjust,10)
ego_df<-ego_df[order(ego_df$p.adjust,decreasing=TRUE),] #order table by p-value
print(nrow(ego_df))
ego_df$Description<-factor(ego_df$Description,level=ego_df$Description)
ego_df$gene_ratio<-sapply(ego_df$GeneRatio, function(x) as.numeric(strsplit(x,split='/')[[1]][1])/as.numeric(strsplit(x,split='/')[[1]][2]))
#if more than 10 significant terms only plot the 20 most significant
if(nrow(ego_df)>=10){
png(paste0('clusters',k,'_',i,'_',GOtype,'.png'),width=650,height=475)
print(ggplot(ego_df[((nrow(ego_df)-19):nrow(ego_df)),],aes(x=neglog10padj,y=Description,fill=gene_ratio))_and_geom_bar(stat='identity')_and_theme_classic()_and_
GOtypes<-c('ALL')
for(GOtype in GOtypes){
for(i in 1:k){
geneList<-subset(clusters,cluster==i)$gene
ego <- enrichGO(geneList, OrgDb = "org.Hs.eg.db", ont=GOtype, pAdjustMethod='fdr', pvalueCutoff=0.01,universe=bg_universe,keyType='SYMBOL',minGSSize=20,maxGSSize=500)
ego_df<-data.frame(ego,stringsAsFactors = FALSE)
ego_df<-ego_df[order(ego_df$p.adjust),]
write.csv(ego_df[,c(2,3,4,6,8)],file = paste0('clusters_',i,'_',GOtype,'.csv'),quote=FALSE,row.names=FALSE)
ego_df$neglog10padj<--log(ego_df$p.adjust,10)
ego_df<-ego_df[order(ego_df$p.adjust,decreasing=TRUE),] #order table by p-value
print(nrow(ego_df))
ego_df$Description<-factor(ego_df$Description,level=ego_df$Description)
ego_df$gene_ratio<-sapply(ego_df$GeneRatio, function(x) as.numeric(strsplit(x,split='/')[[1]][1])/as.numeric(strsplit(x,split='/')[[1]][2]))
#if more than 10 significant terms only plot the 20 most significant
if(nrow(ego_df)>=10){
png(paste0('clusters',k,'_',i,'_',GOtype,'.png'),width=650,height=475)
print(ggplot(ego_df[((nrow(ego_df)-19):nrow(ego_df)),],aes(x=neglog10padj,y=Description,fill=gene_ratio))+geom_bar(stat='identity')+theme_classic()+
scale_x_continuous(expand=c(0,0))+labs(fill = 'Gene Ratio')+xlab('-log10 adjusted p-val')+ylab('')+theme(axis.text=element_text(size=12),axis.title=element_text(size=12)))
dev.off()
}else{
png(paste0('clusters',k,'_',i,'_',GOtype,'.png'),width=650,height=475)
print(ggplot(ego_df,aes(x=neglog10padj,y=Description,fill=gene_ratio))+geom_bar(stat='identity')+theme_classic()+
scale_x_continuous(expand=c(0,0))+labs(fill = 'Gene Ratio')+xlab('-log10 adjusted p-val')+ylab('')+theme(axis.text=element_text(size=12),axis.title=element_text(size=12)))
dev.off()
}
rm(ego,ego_df,geneList)
}}
